// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()
const db = cloud.database();
// 云函数入口函数
// 添加一条数据到collect表
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  let goodsId = event.id;

  let goodsRes = await db.collection("goods").doc(goodsId).get();

  let goods = goodsRes.data;


  let collect = {
    openid:wxContext.OPENID,
    goods,
    goodsId:goods._id
  };

  let result = await db.collection("collect").add({
    data:collect
  });
  return {
    code:200,
    msg:"添加收藏成功"
  }
}